package com.netbetter.langzheng.plugin.fileManager.context;

import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.TreeLoader;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.widget.tree.TreeItem;
import com.netbetter.langzheng.commons.constants.AppEvents;
import com.netbetter.langzheng.plugin.fileManager.model.FileModel;

/**
 * 树节点选中激活的事件
 * 
 *@author 嘉陵江里捉鱼 email:tang7259@163.com
 *@version 1.0
 *@time 2008-9-11 下午10:00:54
 */
public class ChangeTreeItemEventContext {

    /**
     * 当前节点FileModel对象
     */
    protected static FileModel             fileModel;
    protected static TreeLoader<ModelData> loader;

    public static TreeLoader<ModelData> getLoader() {
        return loader;
    }

    public static void setLoader(TreeLoader<ModelData> loader) {
        ChangeTreeItemEventContext.loader = loader;
    }

    public static FileModel getFileModel() {
        return fileModel;
    }

    /**
     * 当前选中树节点
     */
    private static TreeItem treeItem;

    /**
     * 激活事件
     * 
     * @param fileModel
     * @param treeItem
     */
    public static void attach(FileModel fileModel, TreeItem treeItem) {
        ChangeTreeItemEventContext.fileModel = fileModel;
        ChangeTreeItemEventContext.treeItem = treeItem;
        if (fileModel.getIsDirectory()) {
            Dispatcher.forwardEvent(AppEvents.ChangeTreeItem);
        }
    }

    public static TreeItem getTreeItem() {
        return treeItem;
    }

}
